home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / chrome / dwhelper.jar / content / twitter.xml < prev    next >
Extensible Markup Language  |  2010-01-15  |  8KB  |  269 lines

  1. <?xml version="1.0"?>
  2. <!-- *****************************************************************************
  3.  *            Copyright (c) 2006-2007 Michel Gutierrez. All Rights Reserved.
  4.  ****************************************************************************** -->
  5. <!DOCTYPE bindings SYSTEM "chrome://dwhelper/locale/dwhelper.dtd" >
  6.  
  7. <bindings xmlns="http://www.mozilla.org/xbl"
  8.     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.     xmlns:html="http://www.w3.org/1999/xhtml"
  10.     xmlns:xbl="http://www.mozilla.org/xbl">
  11.  
  12.     <binding id="TwitterPref" extends="widgets.xml#widget">
  13.  
  14.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  15.             <vbox flex="1">
  16.                 <spacer flex="1"/>
  17.                 <grid flex="1">
  18.                     <columns>
  19.                         <column/>
  20.                         <column flex="1"/>
  21.                     </columns>
  22.                     <rows>
  23.                         <row anonid="xStatusRow" hidden="true">
  24.                             <label value="&twitter.pref.last-check;"/>
  25.                             <description anonid="xStatus" class="feature-descr" style="max-height: 20px; overflow: auto;"/>
  26.                         </row>
  27.                         <row align="center">
  28.                             <label value="&twitter.pref.username;"/>
  29.                             <textbox anonid="xUsername" oninput="this.parentNode.parentNode.parentNode.parentNode.parentNode.changedCredentials()"/>
  30.                         </row>
  31.                         <row align="center">
  32.                             <label value="&twitter.pref.password;"/>
  33.                             <DHPassword anonid="xPassword" oninput="this.parentNode.parentNode.parentNode.parentNode.parentNode.changedCredentials()"/>
  34.                         </row>
  35.                     </rows>
  36.                 </grid>
  37.                 <checkbox anonid="xTag" label="&twitter.label.tag-message;"/>
  38.                 <spacer flex="1"/>
  39.                 <hbox>
  40.                     <button anonid="xCreateBut" label="&mp3tunes.pref.create-account;" oncommand="this.parentNode.parentNode.parentNode.signup()"/>
  41.                     <spacer flex="1"/>
  42.                     <button label="&mp3tunes.pref.check-account;" oncommand="this.parentNode.parentNode.parentNode.verifyCredentials()"/>
  43.                 </hbox>
  44.             </vbox>
  45.             <children style="display: none;"/>
  46.         </xbl:content>
  47.  
  48.         <implementation>
  49.  
  50.             <constructor>
  51.                 <![CDATA[
  52. this.twitter=Components.classes['@downloadhelper.net/twitter-processor;1'].
  53.     getService(Components.interfaces.dhITwitter);
  54. this.setAttribute("onsyncfrompreference","this.onSyncFromPreference(event)");
  55. this.setAttribute("onsynctopreference","this.onSyncToPreference(event)");
  56. var prefService=Components.classes["@mozilla.org/preferences-service;1"]
  57.                                    .getService(Components.interfaces.nsIPrefService);
  58. this.pref=prefService.getBranch("dwhelper.twitter.");
  59. setTimeout(function(_this) { _this.updateStatus(); },0,this);
  60.                 ]]>
  61.             </constructor>
  62.  
  63.             <method name="onSyncFromPreference">
  64.                 <parameter name="event"/>
  65.                 <body>
  66.                 <![CDATA[
  67. this.xUsername.value=this.pref.getCharPref("username");
  68. setTimeout(function(_this) {
  69.     var password=_this.util.getPassword("twitter");
  70.     _this.xPassword.value=(password!=null)?password:"";
  71. },0,this);
  72. this.xTag.checked=this.pref.getBoolPref("tag-message");
  73.                 ]]>
  74.                 </body>
  75.             </method>
  76.  
  77.             <method name="onSyncToPreference">
  78.                 <parameter name="event"/>
  79.                 <body>
  80.                 <![CDATA[
  81. this.pref.setCharPref("username",this.xUsername.value);
  82. if(this.xPassword.valueSet)
  83.     this.util.setPassword("twitter",this.xPassword.value);
  84. this.pref.setBoolPref("tag-message",this.xTag.checked);
  85.                 ]]>
  86.                 </body>
  87.             </method>
  88.  
  89.             <method name="verifyCredentials">
  90.                 <body>
  91.                 <![CDATA[
  92. function VerifyCredentialsObserver(client) {
  93.     this.client=client;
  94. }
  95. VerifyCredentialsObserver.prototype={
  96.     observe: function(subject,topic,data) {
  97.         if(topic=="twitter-credentials") {
  98.             this.client.updateStatus();
  99.         }
  100.     }
  101. }
  102. while(this.xStatus.firstChild)
  103.     this.xStatus.removeChild(this.xStatus.firstChild);
  104. this.xStatus.appendChild(document.createTextNode(this.util.getText("twitter.message.verifying-credentials")));
  105. this.disableAll(true);
  106. this.twitter.verifyCredentials(new VerifyCredentialsObserver(this));
  107.                 ]]>
  108.                 </body>
  109.             </method>
  110.  
  111.             <method name="updateStatus">
  112.                 <body>
  113.                 <![CDATA[
  114. this.disableAll(false);
  115. var status="unchecked";
  116. try {
  117.     status=this.pref.getCharPref("last-status");
  118. } catch(e) {}
  119. this.xStatusRow.setAttribute("hidden","true");
  120. var lastStatusText=null;
  121. switch(status) {
  122.     case "unchecked":
  123.         this.xCreateBut.setAttribute("hidden","false");
  124.         lastStatusText=this.util.getText("twitter.message.account-unchecked");
  125.         break;
  126.     case "succeeded":
  127.         this.xCreateBut.setAttribute("hidden","true");
  128.         lastStatusText=this.util.getText("twitter.message.account-verified");
  129.         break;
  130.     case "failed":
  131.         this.xCreateBut.setAttribute("hidden","false");
  132.         lastStatusText=this.util.getText("twitter.message.account-failed");
  133.         break;
  134. }
  135. if(lastStatusText) {
  136.     while(this.xStatus.firstChild)
  137.         this.xStatus.removeChild(this.xStatus.firstChild);
  138.     this.xStatus.appendChild(document.createTextNode(lastStatusText));
  139.     this.xStatusRow.setAttribute("hidden","false");
  140. }
  141.                 ]]>
  142.                 </body>
  143.             </method>
  144.  
  145.             <method name="disableAll">
  146.                 <parameter name="disable"/>
  147.                 <body>
  148.                 <![CDATA[
  149. var tbs=["xUsername","xPassword"];
  150. for(var i in tbs) {
  151.     this[tbs[i]].disabled=disable;
  152. }
  153.                 ]]>
  154.                 </body>
  155.             </method>
  156.  
  157.             <method name="changedCredentials">
  158.                 <body>
  159.                 <![CDATA[
  160. this.pref.setCharPref("last-status","unchecked");
  161. this.updateStatus();
  162.                 ]]>
  163.                 </body>
  164.             </method>
  165.  
  166.             <method name="signup">
  167.                 <body>
  168.                 <![CDATA[
  169. window.open("https://twitter.com/signup?commit=Join!");
  170.                 ]]>
  171.                 </body>
  172.             </method>
  173.  
  174.                         
  175.         </implementation>
  176.                 
  177.     </binding>
  178.  
  179.     <binding id="TwitterMessage" extends="widgets.xml#widget">
  180.  
  181.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  182.             <vbox flex="1">
  183.                 <hbox>
  184.                     <label anonid="xUser"/>
  185.                     <spacer flex="1"/>
  186.                     <label anonid="xLeft" style="font-size: 24pt;"/>
  187.                 </hbox>
  188.                 <textbox anonid="xText" multiline="true" rows="4" cols="35" style="" oninput="this.parentNode.parentNode.updateLength()"/>
  189.                 <vbox anonid="xSmartNaming" collapsed="true">
  190.                      <description style="font-style: italic; width: 300px;" flex="1">&twitter.message.smartnaming;</description>
  191.                      <hbox>
  192.                         <spacer flex="1"/>
  193.                         <html:a style="display: block;" onclick="this.parentNode.parentNode.parentNode.parentNode.goToSmartnaming();">&twitter.label.go-to-smartnaming;</html:a>
  194.                      </hbox>
  195.                 </vbox>
  196.  
  197.             </vbox>
  198.             <children style="display: none;"/>
  199.         </xbl:content>
  200.  
  201.         <implementation>
  202.  
  203.             <constructor>
  204.                 <![CDATA[
  205. this.twitter=Components.classes['@downloadhelper.net/twitter-processor;1'].
  206.     getService(Components.interfaces.dhITwitter);
  207.                 ]]>
  208.             </constructor>
  209.  
  210.             <property name="value">  
  211.                 <setter>
  212.                 <![CDATA[
  213. this.xText.value=val;
  214. this.updateLength();
  215.                 ]]> 
  216.                 </setter>
  217.                 <getter>
  218.                 <![CDATA[
  219. return this.xText.value;
  220.                 ]]> 
  221.                 </getter>
  222.             </property>
  223.  
  224.             <property name="user">  
  225.                 <setter>
  226.                 <![CDATA[
  227. this.xUser.value=Util.getFText("twitter.label.from-user",[val],1);
  228.                 ]]> 
  229.                 </setter>
  230.             </property>
  231.  
  232.             <property name="smartNaming">  
  233.                 <setter>
  234.                 <![CDATA[
  235. this.xSmartNaming.collapsed=val;
  236.                 ]]> 
  237.                 </setter>
  238.             </property>
  239.  
  240.             <method name="updateLength">
  241.                 <body>
  242.                 <![CDATA[
  243. var left=140-this.twitter.twitterLength(this.xText.value);
  244. this.xLeft.setAttribute("value",""+left);
  245. if(left>=0) {
  246.     this.xLeft.style.color="Black";
  247. } else {
  248.     this.xLeft.style.color="Red";
  249. }
  250.                 ]]>
  251.                 </body>
  252.             </method>
  253.  
  254.             <method name="goToSmartnaming">
  255.                 <body>
  256.                 <![CDATA[
  257. window.open("http://www.downloadhelper.net/smartname.php");
  258.                 ]]>
  259.                 </body>
  260.             </method>
  261.  
  262.  
  263.         </implementation>
  264.         
  265.     </binding>
  266.  
  267.  
  268. </bindings>
  269.